/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CapadeDatos;

import java.sql.Connection;
import java.sql.Statement;
import javax.swing.JOptionPane;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import modelo.beancondicion;
import modelo.beanturno;
/**
 *
 * @author principal
 */
public class Daoturno2 {

    public static  beanturno verturnos( String x){
         beanturno lista = new  beanturno();
    try{
            Connection cn = ConexionBD.getInstance().getConnection();
            Statement stm = cn.createStatement();
            String sql ="Select * from turno where descripcion='"+ x +"';"; // PROCEDIMIENTO ALMACENADO
            ResultSet rs =stm.executeQuery(sql);
            while (rs.next()){
                    lista.setEstado(rs.getString(3));
                   lista.setDescripcion(rs.getString(2));
                   lista.setCod_turno(rs.getInt(1));
                   
        }
    }catch(Exception e){System.out.print(e);
   }return lista;
   }

public void insertarturno( String desc){
        Boolean verdad = false;
    try{
            Connection cn = ConexionBD.getInstance().getConnection();
            Statement stm = cn.createStatement();
            String sql ="Call proc_registrarturno('"
                    + desc + "');";
            if(stm.executeQuery(sql).wasNull()){
               verdad = false;
               JOptionPane.showMessageDialog(null,"NO INGRESADO");
            }
            else {
                verdad = true;
    beanturno n=new beanturno();
                        n=verturnos(desc);
                JOptionPane.showMessageDialog(null,"INGRESADO "+n.getCod_turno()+"-->"+n.getDescripcion()+"-->"+n.getEstado()+"");
            }
    }catch(Exception e){System.out.print(e);
   }
   }
 public static List<beanturno> listaItem1()   {
       Connection conexion=null;
        int I;
       try {
        //Connection cn = ConexionBD.getInstance().getConnection();
        //Statement stm = cn.createStatement();
        conexion=ConexionBD.getInstance().getConnection();
        String sql="Select cod_turno,descripcion from turno";
        Statement st=conexion.createStatement();
        ResultSet rs=st.executeQuery(sql);
        //List<beanmodulo> oListItem=new ArrayList<beanmodulo>();
           ArrayList lista = new ArrayList();
       while(rs.next())
            {
               beanturno modulo=new beanturno();
               modulo.setCod_turno(rs.getInt(1));
               modulo.setDescripcion(rs.getString(2));
               lista.add(modulo);
            }
        return lista;
       }
       catch(Exception ex)
       {
           ex.printStackTrace();
           return null;
       }
       finally
       {
            try
            {
            conexion.close();
            }
            catch (SQLException ex)
            {
              ex.printStackTrace();
            }
       }
   }

}
